package com.pruebas.physics.common;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.view.KeyEvent;

public abstract class AbstractActivity extends Activity {
	protected GLSurfaceView mGLView;
	protected boolean backKeyPressed = false;
	
	@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	if(KeyEvent.KEYCODE_BACK == keyCode && event.getAction() == KeyEvent.ACTION_DOWN){
    		backKeyPressed = true;
    	}
    	return super.onKeyDown(keyCode, event);
    }
	
	@Override
    protected void onPause() {
        super.onPause();
        // The following call pauses the rendering thread.
        // If your OpenGL application is memory intensive,
        // you should consider de-allocating objects that
        // consume significant memory here.
        mGLView.onPause();
        if(backKeyPressed){
	        setResult(RESULT_OK);
	        finish();
        }
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        // The following call resumes a paused rendering thread.
        // If you de-allocated graphic objects for onPause()
        // this is a good place to re-allocate them.
        mGLView.onResume();
    }
}
